home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / faxd / FaxServer.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  10KB  |  248 lines

  1. /*    $Header: /usr/people/sam/fax/faxd/RCS/FaxServer.h,v 1.97 1994/04/10 03:57:26 sam Rel $ */
  2. /*
  3.  * Copyright (c) 1990, 1991, 1992, 1993, 1994 Sam Leffler
  4.  * Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and 
  7.  * its documentation for any purpose is hereby granted without fee, provided
  8.  * that (i) the above copyright notices and this permission notice appear in
  9.  * all copies of the software and related documentation, and (ii) the names of
  10.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11.  * publicity relating to the software without the specific, prior written
  12.  * permission of Sam Leffler and Silicon Graphics.
  13.  * 
  14.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  15.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  16.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  17.  * 
  18.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23.  * OF THIS SOFTWARE.
  24.  */
  25. #ifndef _FaxServer_
  26. #define    _FaxServer_
  27. /*
  28.  * Fax Modem and Protocol Server.
  29.  */
  30. #include <stdarg.h>
  31.  
  32. #include "FaxMachineLog.h"
  33. #include "FaxModem.h"
  34. #include "ModemConfig.h"
  35. #include "FaxRequest.h"
  36. #include "FaxTrace.h"
  37.  
  38. #include <Dispatch/iohandler.h>
  39. #include <sys/time.h>
  40.  
  41. class RegExArray;
  42. class FaxSendOpArray;
  43. class faxServerApp;
  44. class Getty;
  45. class FaxMachineInfo;
  46. class FaxMachineLog;
  47. class UUCPLock;
  48. class FaxRecvInfo;
  49. class FaxRecvInfoArray;
  50. class DialStringRules;
  51.  
  52. /*
  53.  * This class defines the ``server process'' that manages the fax
  54.  * modem and implements the necessary protocol above the FaxModem
  55.  * driver interface.  When the server is multi-threaded, this class
  56.  * embodies a separate thread.
  57.  */
  58. class FaxServer : public IOHandler {
  59. private:
  60.     enum FaxServerState {
  61.     BASE        = 0,
  62.     RUNNING        = 1,
  63.     MODEMWAIT    = 2,
  64.     LOCKWAIT    = 3,
  65.     GETTYWAIT    = 4,
  66.     SENDING        = 5,
  67.     ANSWERING    = 6,
  68.     RECEIVING    = 7,
  69.     };
  70.     FaxServerState state;
  71.     faxServerApp* app;            // client server app
  72.     Getty*    getty;            // currently active getty
  73.     UUCPLock*    modemLock;        // UUCP interlock
  74.     FILE*    statusFile;        // server status file
  75.     fxBool    abortCall;        // abort current send
  76.     fxBool    deduceComplain;        // if true, complain when can't deduce
  77. // generic modem-related stuff
  78.     int        modemFd;        // open modem file
  79.     fxStr    modemDevice;        // name of device to open
  80.     fxStr    modemDevID;        // device identifier
  81.     FaxModem*    modem;            // modem driver
  82.     ModemConfig    modemConfig;        // modem configuration info
  83.     time_t    lastConfigModTime;    // last mod time of configuration file
  84.     SpeakerVolume speakerVolume;    // volume control
  85.     BaudRate    curRate;        // current baud rate
  86. // server configuration
  87.     u_short    ringsBeforeAnswer;    // # rings to wait
  88.     fxStr    qualifyTSI;        // if set, no recv w/o acceptable tsi
  89.     int        noCarrierRetrys;    // # times to retry on no carrier
  90.     mode_t    recvFileMode;        // protection mode for received files
  91.     mode_t    deviceMode;        // protection mode for modem device
  92.     mode_t    logMode;        // protection mode for log files
  93.     int        tracingLevel;        // tracing level w/o session
  94.     int        logTracingLevel;    // tracing level during session
  95.     int        tracingMask;        // tracing level control mask
  96.     fxStr    gettyArgs;        // getty arguments
  97.     fxBool    adaptiveAnswer;        // answer as data if fax answer fails
  98.     short    answerBias;        // rotor bias applied after good calls
  99.     u_short    answerRotor;        // rotor into possible selections
  100.     u_short    answerRotorSize;    // rotor table size
  101.     AnswerType    answerRotary[3];    // rotary selection of answer types
  102.     u_int    requeueTTS[7];        // requeue intervals[CallStatus code]
  103.     u_int    requeueProto;        // requeue interval after protocol error
  104.     u_int    requeueOther;        // requeue interval after other problem
  105.     u_int    pollModemWait;        // polling interval in modem wait state
  106.     u_int    pollLockWait;        // polling interval in lock wait state
  107. // phone number-related state
  108.     fxStr    longDistancePrefix;    // prefix str for long distance dialing
  109.     fxStr    internationalPrefix;    // prefix str for international dialing
  110.     fxStr    myAreaCode;        // local area code
  111.     fxStr    myCountryCode;        // local country code
  112.     DialStringRules* dialRules;        // dial string rules
  113.     fxStr    FAXNumber;        // phone number
  114. // group 3 protocol-related state
  115.     Class2Params clientCapabilities;    // received client capabilities
  116.     Class2Params clientParams;        // current session parameters
  117. // buffered i/o stuff
  118.     short    rcvCC;            // # bytes pending in rcvBuf
  119.     short    rcvNext;        // next available byte in rcvBuf
  120.     u_char    rcvBuf[1024];        // receive buffering
  121. // for fax reception ...
  122.     fxBool    timeout;        // timeout during data reception
  123.     fxBool    okToRecv;        // ok to accept stuff for this session
  124.     fxStr    recvTSI;        // sender's TSI
  125.     fxStr    hostname;        // host on which fax is received
  126.     time_t    recvStart;        // starting time for document receive
  127.     time_t    lastPatModTime;        // last mod time of patterns file
  128.     RegExArray*    tsiPats;        // acceptable recv tsi patterns
  129. // send+receive stats
  130.     u_int    npages;            // # pages sent/received
  131. // logging and tracing
  132.     FaxMachineLog* log;            // current log device
  133.  
  134.     friend class FaxModem;
  135.     friend class faxServerApp;    // XXX for access to setServerStatus, yech
  136.  
  137.     static int pageWidthCodes[8];    // map wd to pixel count
  138.     static int pageLengthCodes[4];    // map ln to mm length
  139.  
  140. // FAX transmission protocol support
  141.     void    sendFax(FaxRequest& fax, FaxMachineInfo&, const fxStr& number);
  142.     fxBool    sendPrepareFax(FaxRequest&, FaxMachineInfo&, fxStr& emsg);
  143.     fxBool    sendClientCapabilitiesOK(FaxMachineInfo&, u_int nsf, fxStr&);
  144.     fxBool    sendFaxPhaseB(FaxRequest&, FaxMachineInfo&, const fxStr& file);
  145.     void    sendPoll(FaxRequest& fax, fxBool remoteHasDoc);
  146.     fxBool    sendSetupParams(TIFF*, Class2Params&, FaxMachineInfo&, fxStr&);
  147.     fxBool    sendSetupParams1(TIFF*, Class2Params&, FaxMachineInfo&, fxStr&);
  148.     void    sendFailed(FaxRequest& fax,
  149.             FaxSendStatus, const char* notice, u_int tts = 0);
  150. // FAX reception support
  151.     fxBool    recvFax();
  152.     TIFF*    setupForRecv(const char* op, FaxRecvInfo&, FaxRecvInfoArray&);
  153.     fxBool    recvDocuments(const char* op, TIFF*,
  154.             FaxRecvInfo&, FaxRecvInfoArray&, fxStr& emsg);
  155.     fxBool    recvFaxPhaseB(TIFF* tif, int& ppm, fxStr& emsg);
  156.     void    recvComplete(FaxRecvInfo&, time_t, const fxStr& emsg);
  157.     fxBool    pollFaxPhaseB(const char* cig, FaxRecvInfoArray&, fxStr& emsg);
  158.     void    updateTSIPatterns();
  159.     RegExArray*    readTSIPatterns(FILE*);
  160. // miscellaneous stuff
  161.     fxBool    setupCall(AnswerType atype, CallType ctype,
  162.             fxBool& waitForProcess, fxStr& emsg);
  163.     fxBool    runGetty(const char* args);
  164.     void    setAnswerRotary(const fxStr& value);
  165. // state-related stuff
  166.     static const char* stateNames[8];
  167.     static const char* stateStatus[8];
  168.  
  169.     fxBool    setupModem();
  170.     fxBool    openDevice(const char* dev);
  171.     fxBool    reopenDevice();
  172.     void    discardModem(fxBool dropDTR);
  173.     void    changeState(FaxServerState, long timeout = 0);
  174.     void    setServerStatus(const char* fmt, ...);
  175.     fxBool    abortRequested();
  176.     void    setProcessPriority(FaxServerState s);
  177. // modem i/o support
  178.     int        inputReady(int);
  179.     void    timerExpired(long, long);
  180.     void    childStatus(pid_t, int);
  181.     int        getModemLine(char buf[], u_int bufSize, long ms = 0);
  182.     int        getModemChar(long ms = 0);
  183.     void    flushModemInput();
  184.     fxBool    putModem(const void* data, int n, long ms = 0);
  185.     fxBool    putModem1(const void* data, int n, long ms = 0);
  186.     void    startTimeout(long ms);
  187.     void    stopTimeout(const char* whichdir);
  188. // modem line control
  189.     fxBool    sendBreak(fxBool pause);
  190.     fxBool    setBaudRate(BaudRate rate);
  191.     fxBool    setBaudRate(BaudRate rate, FlowControl i, FlowControl o);
  192.     fxBool    setXONXOFF(FlowControl i, FlowControl o, SetAction act);
  193.     fxBool    setDTR(fxBool on);
  194.     fxBool    setInputBuffering(fxBool on);
  195.     fxBool    modemStopOutput();
  196.     void    modemFlushInput();
  197.  
  198. // general trace interface (used by modem classes)
  199.     void    traceStatus(int kind, const char* fmt ...);
  200.     void    vtraceStatus(int kind, const char* fmt, va_list ap);
  201.     void    traceModemIO(const char* dir, const u_char* buf, u_int cc);
  202. // FAX receiving protocol support (used by modem classes)
  203.     void    recvDCS(const Class2Params&);
  204.     void    recvNSF(u_int);
  205.     fxBool    recvCheckTSI(const fxStr& tsi);
  206.     void    recvSetupPage(TIFF* tif, long group3opts, int fillOrder);
  207. public:
  208.     FaxServer(faxServerApp* app, const fxStr& deviceName, const fxStr& devID);
  209.     ~FaxServer();
  210.  
  211.     void open();
  212.     void close();
  213.     void initialize(int argc, char** argv);
  214.  
  215.     void setDialRules(const char* filename);
  216.     fxStr canonicalizePhoneNumber(const fxStr& number);
  217.     fxStr prepareDialString(const fxStr& ds);
  218.  
  219.     fxBool restoreState(const fxStr& filename);
  220.     void restoreStateItem(const char* line);
  221.  
  222.     void setModemNumber(const fxStr& number);    // fax phone number
  223.     const fxStr& getModemNumber();
  224.  
  225.     fxBool modemReady() const;
  226.     fxBool modemSupports2D() const;
  227.     fxBool modemSupportsEOLPadding() const;
  228.     fxBool modemSupportsVRes(float res) const;
  229.     fxBool modemSupportsPageWidth(u_int w) const;
  230.     fxBool modemSupportsPageLength(u_int l) const;
  231.  
  232.     fxBool serverBusy() const;
  233.  
  234.     void setSessionTracing(int level);        // tracing during send+receive
  235.     int getSessionTracing();
  236.     void setServerTracing(int level);        // tracing outside send+receive
  237.     int getServerTracing();
  238.     void setModemSpeakerVolume(SpeakerVolume);    // speaker volume
  239.     SpeakerVolume getModemSpeakerVolume();
  240.     void setRingsBeforeAnswer(int rings);    // rings to wait before answer
  241.     int getRingsBeforeAnswer();
  242.  
  243.     void sendFax(FaxRequest&, FaxMachineInfo&);    // client-server send interface
  244.     void answerPhone(AnswerType, fxBool force);    // client-server recv interface
  245.     void abortSession();            // abort send/receive session
  246. };
  247. #endif /* _FaxServer_ */
  248.